package Controller.SCServlet;

import Dao.SCDao;
import com.alibaba.fastjson.JSON;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

@WebServlet("/sc_batchDelete")
public class sc_batchDelete extends HttpServlet {
    SCDao scDao = new SCDao();
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        String sc_list_str = req.getParameter("sc_list_str");
        String[] sc_list = sc_list_str.split(",");
        ArrayList<String[]> sc_list_arr = new ArrayList<>();
        for (String sc_sno : sc_list) {
            String[] sno_cno = sc_sno.split("&");
            scDao.delete(sno_cno[0], sno_cno[1]);
        }
        Map<String, Object> map = new HashMap<>();
        map.put("code", 200);
        map.put("msg", "批量删除成功!");
        resp.getWriter().write(JSON.toJSONString(map));
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }
}
